package com.zmn.oms.admin.controller.callpop;

import com.zmn.common.dictionary.GlobalDict;
import com.zmn.consts.GlobalConsts;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.mcc.cas.web.StaffAdminService;
import com.zmn.oms.admin.controller.OmsBaseController;
import com.zmn.oms.business.interfaces.callinfo.CallInfoBService;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.entity.callinfo.CallInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 类描述：呼叫信息录入
 *
 * @author yule
 * @date 2019/07/01 12:40
 */
@Controller
@RequestMapping("/call/info")
public class CallInfoController extends OmsBaseController {

	@Autowired
	private CallInfoBService callInfoBService;

	/**
	 * 新增订单
	 *
	 * @return
	 */
	@RequestMapping(value = "add")
	public ModelAndView add() {
		ModelAndView mav = new ModelAndView("call/info/add");
		// 性别
		mav.addObject("gender", super.dictModel2KVDict(GlobalDict.getGenderList()));
		// 服务分类
		mav.addObject("servCategList", super.getShowServCategList());
		// 渠道列表 1不禁用，2禁用
		// mav.addObject("channelList", super.getAllowChannelList(GlobalConsts.PLAT_MARK_ZMN));

		// 啄木鸟平台&非厂商渠道&渠道数据权限&允许后台录单&状态正常的渠道
		mav.addObject("channelList", super.getChannelListByDept(GlobalConsts.PLAT_MARK_ZMN));
		// mav.addObject("channelList", AllowChannelListConsts.getInstance().getCallAddChannelList());

		// 产品
//		List<KVDict> servProductList = super.getServProductList(GlobalConsts.PLAT_MARK_ZMN, null, GlobalConsts.YES, false);
//		servProductList.addAll(super.getServProductListByDisableShowProduct(GlobalConsts.PLAT_MARK_ZMN, null));// 加入禁用前台产品关联的后台产品
//		mav.addObject("servProductList", servProductList);
		// 品牌
		mav.addObject("brandList", super.getBrandList());
		// 自动外呼
		mav.addObject("automatic", super.dictModel2KVDict(OrderConsts.getCallAutomaticList()));
		// 省份
		mav.addObject("provinceList", super.getAllProvinceList());
		// 城市ID
		mav.addObject("cityList", super.getAllCityList());
		return mav;
	}

	/**
	 * 呼叫信息录入
	 *
	 * @return
	 */
	@RequestMapping(value = "save", method = RequestMethod.POST)
	@ResponseBody
	public ResultDTO saveOrder(@RequestBody CallInfo callInfo) {
		try {

			logger.debug("呼叫信息录入：{}", callInfo);
			LoginStaff loginStaff = StaffAdminService.currentStaff();
			callInfo.setCreater(loginStaff.getRealName());
			ResultDTO isSuccess = callInfoBService.insertCallInfo(callInfo);
			return isSuccess;

		} catch (Exception e) {
			e.printStackTrace();
			return ResultDTO.fail(e.getMessage());
		}
	}

}
